﻿namespace MefContrib.Models.Provider
{
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Primitives;

    public class ExtendedExport<TContract, TMetadata> : Export<TContract, TMetadata>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="core"></param>
        public ExtendedExport(Export core)
        {
            this.Core = core;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        private Export Core { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public override ExportDefinition Definition
        {
            get
            {
                return this.Core.Definition;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        private object ExportedCoreObject { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override object GetExportedObjectCore()
        {
            if (this.ExportedCoreObject == null)
            {
                this.ExportedCoreObject = this.Core.GetExportedObject();
            }

            return this.ExportedCoreObject;
        }
    }
}
